#!/usr/bin/perl -w
#
# This shouldn't be used unless Curses::UI dies unexpectedly and
# Warcarrier cannot re-connect back to the current running CSV 
# from Airodump-NG
#
use warnings;
use strict;
if($ARGV[0]){ ### Arguments ###
	if($ARGV[0] =~ m/--?h(elp)?/){ # program flow here:
		usage();
	}elsif($ARGV[0] eq 'logs'){
		logs();
	}elsif($ARGV[0] eq 'sys'){
		sys();
	}elsif($ARGV[0] eq 'proc'){
		proc();
	}elsif($ARGV[0] eq 'all'){
		sys();proc();logs();
	}else{
		usage();
	}
}else{
	usage();
}
sub logs{ # subroutine for logs
	system("rm logs/txt/* 2>/dev/null"); # Catchme-NG, etc.
	system("rm logs/html/* 2>/dev/null"); # HTML logs and Google Maps
	system("rm logs/capfiles/* 2>/dev/null"); # Airodump PCAP (Can get rather large!)
	system("rm logs/bluetooth/* 2>/dev/null"); # Ubertooth Site Record
}
sub sys{ # subroutine for system files
	system("rm bt.* 2>/dev/null"); # bluetooth dump file from hcitool: Net::Bluetooth
	system("rm gps.* 2>/dev/null"); # dump files from GPSD
	system("rm wc.* 2>/dev/null"); # dunno i'm druonkl
	system("rm ubt.out 2>/dev/null"); # Uberooth output formatted
	system("rm ubt.raw 2>/dev/null"); # UBertooth output formatted by nice
}
sub proc{ # subroutine for runaway processes
	system("killall airodump-ng 2>/dev/null");
	my $killcmd = "ps aux | grep [s]pectool | awk '{print \$2}' | xargs kill 2>/dev/null";
	system($killcmd);
}
sub usage{ # whoops
	print "Usage: ./wcclean (proc|sys|logs|all)\n".  
	  "  all:\teverything.\n  proc:\tstop runaway processes\n  logs:\tdestroy log\n  sys:\tdestroy system files\n\n";
	exit;
}
print "[ WC ] Warcarrier clean-up completed.\n";
